#pragma once

#include <memory>
#include <vector>

// #include "mdict.h"
// #include "MDX.h"
#include "mdx.h"

// using namespace mdict;
using std::shared_ptr;
using std::string;
using std::vector;
using upMdict = shared_ptr<mdx::Dictionary>;

enum DictFormat {
    DICT_MDX,  // MDict格式
    DICT_DZ,   // stardict格式
};

class DictEngin {
public:
    DictEngin();
    virtual ~DictEngin();

protected:
    virtual QString query(const QString& key);
    uint64_t m_recordCount = 0;

private:
    DictFormat m_fmt = DICT_MDX;
};

class MdxEngin : public DictEngin {
public:
    MdxEngin();
    ~MdxEngin();
    QString next();

    QString query(const QString& key) override;
    QStringList suggest(const QString& prefix);
    bool addDict(const QString& file);
    bool delDict(const QString& file);
    QString metaInfo(const QString& file);
    // void updateDict(const QStringList& files);
    void setCurrentIndex(int idx) { m_currIndex = idx; }

private:
    void loadAllKeys();

private:
    upMdict m_mdx;
    QMap<QString, upMdict> m_dicts;
    // QStringList m_files;
    // vector<key_list_item*> m_items;
    uint64_t m_currIndex = 0;
};
